//
//  SRBookCatalogueSectionHeaderView.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/4/19.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRBookCatalogueSectionHeaderView.h"

NSString *const kSRBookCatalogueSectionHeaderView = @"SRBookCatalogueSectionHeaderView";

@interface SRBookCatalogueSectionHeaderView ()

@property (strong, nonatomic) UIView *leftView;


@end

@implementation SRBookCatalogueSectionHeaderView


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    
    return self;
}


- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupView];
    }
    
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    
    return self;
}


- (void)setupView {
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    bgView.backgroundColor = [UIColor clearColor];
    self.backgroundView = bgView;
    
    if (!self.titleLabel) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:self.titleLabel];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        
        self.titleLabel.font = css.fontOfH3;
        self.titleLabel.textColor = css.color_4;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).offset(15);
            make.trailing.equalTo(self.contentView).offset(-15);
            make.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView);
        }];
    }
    
    if (!self.leftView) {
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectZero];
        leftView.backgroundColor = css.color_7;
        [self.contentView addSubview:leftView];
        self.leftView = leftView;
        
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView);
            make.width.mas_equalTo(7);
            make.height.mas_equalTo(15);
            make.centerY.equalTo(self.contentView);
        }];
        
    }
    
    if (!self.moreButton) {
        self.moreButton = [FZDirectionButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.moreButton];
        self.moreButton.layoutDirection = FZDirectionButtonLayoutHorizontalImageRight;
        
        [self.moreButton setTitle:@"查看更多" forState:UIControlStateNormal];
            //        [self.moreButton setImage:nil forState:UIControlStateNormal];
        [self.moreButton addTarget:self action:@selector(onMoreButton:) forControlEvents:UIControlEventTouchUpInside];
        
        self.moreButton.titleLabel.font = css.fontOfH7;
        [self.moreButton setTitleColor:css.color_4 forState:UIControlStateNormal];
        
        [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
                //            make.leading.equalTo(self.iconImageView.mas_trailing).offset(5);
            make.trailing.equalTo(self.contentView).offset(-15);
            make.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView);
            make.width.mas_equalTo(80);
        }];
    }
    
    self.iconHidden = YES;
    self.moreHidden = YES;
}


- (void)setLeftViewHidden:(BOOL)leftViewHidden {
    _leftViewHidden = leftViewHidden;
    
    self.leftView.hidden = leftViewHidden;
}

- (void)setIconHidden:(BOOL)iconHidden {
    _iconHidden = iconHidden;
//    self.iconImageView.hidden = iconHidden;
//    
//    if (iconHidden) {
//        [self.iconImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.leading.equalTo(self.contentView).offset(15);
//            make.centerY.equalTo(self.contentView);
//            make.height.mas_equalTo(0);
//            make.width.mas_equalTo(0);
//        }];
//    } else {
//        [self.iconImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.leading.equalTo(self.contentView).offset(15);
//            make.centerY.equalTo(self.contentView);
//            make.height.mas_equalTo(18);
//            make.width.mas_equalTo(25);
//        }];
//    }
    
}

- (void)setMoreHidden:(BOOL)moreHidden {
    _moreHidden = moreHidden;
    
    [self.moreButton setHidden:moreHidden];
}

- (void)onMoreButton:(id)sender {
    if (self.touchMoreButtonBlock) {
        self.touchMoreButtonBlock(sender);
    }
}

@end
